From 17441e5e7c55f439ee48687e24514067a7fc2d3c Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 16 Jun 2005 16:06:54 +0000 Subject: [PATCH] Update the RGBA cursor if an icon is set after the cursor has been * gtk/gtkdnd.c: Update the RGBA cursor if an icon is set after the cursor has been constructed. Also handle repeated setting of icons correctly. --- ChangeLog | 6 +++++ ChangeLog.pre-2-10 | 6 +++++ ChangeLog.pre-2-8 | 6 +++++ gtk/gtkdnd.c | 58 ++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 71 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3a5fb3b35b..9fb5aca76b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2005-06-16 Matthias Clasen + + * gtk/gtkdnd.c: Update the RGBA cursor if an + icon is set after the cursor has been constructed. + Also handle repeated setting of icons correctly. + 2005-06-16 Matthias Clasen * gtk/gtkbutton.c (gtk_button_set_image): Add some more diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 3a5fb3b35b..9fb5aca76b 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,9 @@ +2005-06-16 Matthias Clasen + + * gtk/gtkdnd.c: Update the RGBA cursor if an + icon is set after the cursor has been constructed. + Also handle repeated setting of icons correctly. + 2005-06-16 Matthias Clasen * gtk/gtkbutton.c (gtk_button_set_image): Add some more diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 3a5fb3b35b..9fb5aca76b 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,9 @@ +2005-06-16 Matthias Clasen + + * gtk/gtkdnd.c: Update the RGBA cursor if an + icon is set after the cursor has been constructed. + Also handle repeated setting of icons correctly. + 2005-06-16 Matthias Clasen * gtk/gtkbutton.c (gtk_button_set_image): Add some more diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c index 8e9448a8e4..5c35b1e465 100644 --- a/gtk/gtkdnd.c +++ b/gtk/gtkdnd.c @@ -25,6 +25,10 @@ */ #include + +#include +#include + #include "gdkconfig.h" #include "gdk/gdkkeysyms.h" @@ -196,6 +200,7 @@ static void gtk_drag_get_event_actions (GdkEvent *event, static GdkCursor * gtk_drag_get_cursor (GdkDisplay *display, GdkDragAction action, GtkDragSourceInfo *info); +static void gtk_drag_update_cursor (GtkDragSourceInfo *info); static GtkWidget *gtk_drag_get_ipc_widget (GdkScreen *screen); static void gtk_drag_release_ipc_widget (GtkWidget *widget); @@ -620,7 +625,7 @@ gtk_drag_get_cursor (GdkDisplay *display, for (j = 0; j < 10; j++) { const gchar *opt; - const gchar key[32]; + gchar key[32]; gchar **toks; g_snprintf (key, 32, "comment%d", j); @@ -726,6 +731,37 @@ gtk_drag_get_cursor (GdkDisplay *display, return drag_cursors[i].cursor; } +static void +gtk_drag_update_cursor (GtkDragSourceInfo *info) +{ + GdkCursor *cursor; + gint i; + + if (!info->have_grab) + return; + + for (i = 0 ; i < n_drag_cursors - 1; i++) + if (info->cursor == drag_cursors[i].cursor || + info->cursor == info->drag_cursors[i]) + break; + + if (i == n_drag_cursors) + return; + + cursor = gtk_drag_get_cursor (gdk_cursor_get_display (info->cursor), + i, info); + + if (cursor != info->cursor) + { + gdk_pointer_grab (info->ipc_widget->window, FALSE, + GDK_POINTER_MOTION_MASK | + GDK_BUTTON_RELEASE_MASK, + NULL, + cursor, info->grab_time); + info->cursor = cursor; + } +} + /******************** * Destination side * ********************/ @@ -2125,8 +2161,7 @@ gtk_drag_begin_internal (GtkWidget *widget, &info->cur_screen, &info->cur_x, &info->cur_y, NULL); } - g_signal_emit_by_name (widget, "drag_begin", - info->context); + g_signal_emit_by_name (widget, "drag_begin", info->context); /* Ensure that we have an icon before we start the drag; the * application may have set one in ::drag_begin, or it may @@ -2724,13 +2759,20 @@ gtk_drag_set_icon_window (GdkDragContext *context, gtk_drag_remove_icon (info); if (widget) - gtk_widget_ref (widget); + gtk_widget_ref (widget); info->icon_window = widget; info->hot_x = hot_x; info->hot_y = hot_y; info->destroy_icon = destroy_on_release; - + + if (widget && info->icon_pixbuf) + { + g_object_unref (info->icon_pixbuf); + info->icon_pixbuf = NULL; + } + + gtk_drag_update_cursor (info); gtk_drag_update_icon (info); } @@ -2836,8 +2878,14 @@ set_icon_stock_pixbuf (GdkDragContext *context, GtkDragSourceInfo *info; gtk_widget_destroy (window); + info = gtk_drag_get_source_info (context, FALSE); + + if (info->icon_pixbuf) + g_object_unref (info->icon_pixbuf); info->icon_pixbuf = pixbuf; + + gtk_drag_set_icon_window (context, NULL, hot_x, hot_y, TRUE); } else { -- 2.30.2